package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "店铺营业状态设置")
@RestController
@Slf4j
@RequiredArgsConstructor
public class ShopController {
    private final RedisTemplate redisTemplate;
    private final static String REDIS_STATUS_KEY = "SHOP-STATUS";
    @PutMapping("/admin/shop/{status}")
    @ApiOperation("设置商家状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("要设置的状态为：{}",status);
        redisTemplate.opsForValue().set(REDIS_STATUS_KEY,status);
        return Result.success();
    }

    @GetMapping("/admin/shop/status")
    @ApiOperation("获取营业状态")
    public Result getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(REDIS_STATUS_KEY);
        return Result.success(status);
    }
    @GetMapping("/user/shop/status")
    @ApiOperation("获取用户端营业状态")
    public Result getShopStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(REDIS_STATUS_KEY);
        return Result.success(status);
    }

}
